﻿using System;
using System.Collections;
using UnityEngine;

namespace Scripts
{
    public delegate void OnDamageHandle(float hp,float maxHp );
    public class Monster : MonoBehaviour
    {
        private float hp;
        [SerializeField]
        private float maxHp;

        public event OnDamageHandle onDamage;



        private void Start()
        {
            hp = maxHp;
        }
        //受伤
        public void Damage(float value) 
        {
            hp -= value;
            onDamage?.Invoke(hp,maxHp);
            if (hp<=0)
            {
                hp = 0;
                Die();
            }
        }

        private void Die()
        {
            MonsterCreater.DestoryMonster(this.gameObject);
        }


    }
}